﻿package com.skillscoach  {
	
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	
	
	public class Seekbar extends MovieClip{
		
		private var timerDisplay:Timer;	
		private var playerTimer:Timer;	
		public var videoClip:MovieClip;
		private const TIMER_DELAY:int	= 10;
		public var videoPlayPauseBtn:MovieClip;
		
		
		public static const HOURS:uint = 2;
		public static const MINUTES:uint = 1;
		public static const SECONDS:uint = 0;
		
		
		public function Seekbar()  
		{
			// constructor code
			
			seekmask.scaleX = 0;
		}
		
		public function initControls( ):void
		{
			
			
			//playerTimer = pTimer;
			//positionHandle.addEventListener(MouseEvent.MOUSE_DOWN,mDown);			
			//timerDisplay = new Timer(TIMER_DELAY);			
			//timerDisplay.addEventListener(TimerEvent.TIMER, updateDisplay);
			//timerDisplay.start();
		}
		public function updateVideoStatus(e:Event):void
		{
			trace(e.target.objInfo.duration);
		}
		 

		public function progressHandler(curPos:Number, totalLength:Number):void
		{
			
			var pos:Number = curPos/totalLength;
			
			
			seekmask.scaleX = curPos/totalLength;
			
			if(pos <= 1)
			{
				if(pos==1)
				{
					resetSeek();
				}
				seekmask.scaleX = pos ;
				this.timerText_txt.text = formatTime(curPos)+ "/" + formatTime(totalLength);

			}else
			{
				seekmask.scaleX = 1;
			}
			seekbarBtn.x = seekmask.width-9;
			
		}
		public function resetSeek():void
		{
			seekmask.scaleX = 0;
			this.timerText_txt.text = "00:00/00:00";
			seekbarBtn.x = 0;
		}
		
		private function formatTime(time:Number, detailLevel:uint = 2):String
		{
			
			var minutes:uint = time/60;
			var seconds:uint = (time%60);			
			var minuteString:String = detailLevel >= MINUTES ? ((detailLevel == HOURS && minutes <10 ? "0":"") + minutes + ":"):"";
			var secondString:String = ((seconds < 10 && (detailLevel >= MINUTES)) ? "0":"") + seconds;
			return minuteString + secondString;
			
		}
		
		
		
	}
	
}
